我从3天前就一直在努力解决这个问题而且我没有找到为什么mirar.db没有保存信息的原因,你们有没有人知道为什么它不能录制?我将非常感谢您的帮助
<?php
$conexion = new SQLite3('mirar.db') or die ("Ha sido imposible establecer la conexion");
$consulta =
<<<SQL
CREATE TABLE if not exists inventory(StockNumber INTEGER PRIMARY KEY,Descrip VARCHAR(50),OnHandQuan INTEGER,PackQty INTEGER,PackCost FLOAT);
INSERT INTO inventory(StockNumber,Descrip,OnHandQuan,PackQty,PackCost)VALUES (51002,'AA Dry Cells 4 Pack',173,12,9.00);
INSERT INTO inventory(StockNumber,Descrip,OnHandQuan,PackQty,PackCost)VALUES (51004,'AA Dry Cells 8 Pack',5,12,16.80);
INSERT INTO inventory(StockNumber,Descrip,OnHandQuan,PackQty,PackCost)VALUES (43512,'10W-30 Motor Oil, Quart',36,12,18.20);
INSERT INTO inventory(StockNumber,Descrip,OnHandQuan,PackQty,PackCost)VALUES (51013,'D Dry Cells 8 Pack',19,12,90.20);
INSERT INTO inventory(StockNumber,Descrip,OnHandQuan,PackQty,PackCost)VALUES (23155,'Shovel Pointed Long Handle',1500,1,9.82);
INSERT INTO inventory(StockNumber,Descrip,OnHandQuan,PackQty,PackCost)VALUES (51001,'AAA Dry Cells 4 Pack ',92,12,9.00);
INSERT INTO inventory(StockNumber,Descrip,OnHandQuan,PackQty,PackCost)VALUES (43111,'White Gas Gallon Can',14,4,14.75);
SQL;
//Insertar contenido en la Tabla-------
$resultado = $conexion->query($consulta);
if (!$resultado){
echo "error";}
else { echo "Tabla Mirar creada correctamente<br>\n";};
//Cerrar la Conexion-------------------
$conexion->close();
?>
答案 0 :(得分:0)
在您的表中StockNumber
是您不必为其插入数据的主键。它会自动添加。
尝试删除它并再试一次:
CREATE TABLE if not exists inventory(StockNumber INTEGER PRIMARY KEY,Descrip VARCHAR(50),OnHandQuan INTEGER,PackQty INTEGER,PackCost FLOAT);
INSERT INTO inventory(Descrip,OnHandQuan,PackQty,PackCost)VALUES ('AA Dry Cells 4 Pack',173,12,9.00);
INSERT INTO inventory(Descrip,OnHandQuan,PackQty,PackCost)VALUES ('AA Dry Cells 8 Pack',5,12,16.80);
INSERT INTO inventory(Descrip,OnHandQuan,PackQty,PackCost)VALUES ('10W-30 Motor Oil, Quart',36,12,18.20);
INSERT INTO inventory(Descrip,OnHandQuan,PackQty,PackCost)VALUES ('D Dry Cells 8 Pack',19,12,90.20);
INSERT INTO inventory(Descrip,OnHandQuan,PackQty,PackCost)VALUES ('Shovel Pointed Long Handle',1500,1,9.82);
INSERT INTO inventory(Descrip,OnHandQuan,PackQty,PackCost)VALUES ('AAA Dry Cells 4 Pack ',92,12,9.00);
INSERT INTO inventory(Descrip,OnHandQuan,PackQty,PackCost)VALUES ('White Gas Gallon Can',14,4,14.75);
SQL;
简答:一个声明为INTEGER PRIMARY KEY的列 自动增量。
答案 1 :(得分:0)
解决方案是使用$ resultado = $ conexion-&gt; exec($ consulta); 谢谢!