If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then a slightly different ROWID selection algorithm is used. Number or records added : 35 Difference with AUTOINCREMENT & INTEGER PRIMARY KEY (35, 'Rows Noump', 'Six', 88, 'female') " Įcho " Number of records added : ".$sql->rowCount() We can get number of records added by using rowCount() $query="INSERT INTO `student` ID of the new record is : 36 Adding multiple records $msg=" Database problem, please contact site admin " Print_r($sql->errorInfo()) // if any error is there it will be posted $sql->bindParam(':gender',$gender,PDO::PARAM_STR, 10) Įcho "ID of the new record is : ".$my_conn->lastInsertId() $my_conn = null Using PDO with Parameter query // Create (connect to) SQLite database in file $sql=$my_conn->prepare("INSERT INTO student (name,class,mark,gender)Įcho " Record added ID: ". $my_conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION) If the existing highest id is 35 then 36 is inserted as ID by SQLite for the new record. This unique number or ID is the next highest available ID of the primary key column. After successful addition of record SQLite will assign the unique number to the ID column ( ROWID ). Here we are added the name, class, mark and gender columns of the new record. $count=$my_conn->prepare("CREATE TABLE IF NOT EXISTSīy using INSERT query we will add new record. We will use $my_conn to execute our query. $my_conn = new PDO('sqlite:'.dirname(_FILE_).'/test.db') // same location $my_conn = new PDO('sqlite:D:\\sqlite-data\\my_student.db') // different path $my_conn = new PDO('sqlite:my_student.sqlite3') // same path as file execution Create (connect to) SQLite database in file Or use one of this line to create database at different locations. $my_conn = new PDO('sqlite:my_student.sqlite3') We will create the database and connection object. PHP SQLite insert record and get lastInsertId()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |