I have this class for my DB.
When I insert a singular function (a successful one), $ id = mysql_insert_id (); Returns 0 to me Why?
I want to get my auto_interpret ID.
What am I doing?
Thank you!
class database {// care private $ connectionString = "mysql: host = localhost; dbname = practica"; Private $ user = "root"; // usarario de la BBDD permit private $ password = "root" for personal services; Private $ db; Private Function Connect () {$ flag = true; Try {$ this-> db = new PDO ($ this-> connection string, $ this-> user, $ this-> password); } Hold (PDOException $ e) {$ flag = false; } Return $ Flag; } Disconnect Personal Function () {$ this- & gt; Db = null; } Public Function Accolve ($ sql, $ vector) {// Insert, Update, Delete if ($ this-> Connect ()) {$ fla = "products"; $ Posicion = strpos ($ sql, $ fla); If ($ posicion === incorrect) // Normal {// code} and // Exxst. X product x extract ID idel prod Insertat {$ sentencia = $ this-> Db- & gt; Ready ($ sql); $ Sentencia-> Execute ($ vector); $ Id = mysql_insert_id (); // problem here $ cuenta = $ sentencia-> Is puncticount (); Echo $ id; // Prints a 0: () $ the-> Disconnect ();} and {$ cuenta = -1;} Return $ cuenta;}
No comments:
Post a Comment