php/mysql insert into query returns null -
i struggling project want read sql file formatted in specific way , execute queries in it. need check if first query has been executed in order continue. first query returns null value. can me please ? tried mysql error returns nothing too. here code.
<?php $inserts = file_get_contents($nom_definitif); $inserts = preg_replace('/--+\s.*/i', "", $inserts); $inserts = preg_split("/;/si", $inserts); $insert = str_replace('insert into', '', $inserts[0] . " ;"); $res_insert_etab = phpadm_dbquery('insert ' . $insert); //this returns name of database echo "db ".$phpadm_config['dbname_etablissements']."<br>"; //but returns null echo "res_insert: ".$res_insert_etab."<br>"; if($res_insert_etab){ //get last inserted id $last_etab_id = phpadm_dbinsertid(); //execute create database query $create_query = str_replace('###_###etablissement_###_###', 'etablissement_'.$last_etab_id, $inserts[1]. " ;"); mysql_db_query($phpadm_config['dbname_etablissements'],$create_query); echo "lastid ".$last_etab_id; //$inserts = preg_replace($inserts[0], "", $inserts); $i=0; foreach ($inserts $insert) { // 2 premières instructions exéctuées au dessus if($i>1){ $insert = str_replace('insert into', '', $insert); if(strlen($insert)>strlen('insert into')){ $insert = str_replace('###_###etablissement_###_###', 'etablissement_'.$last_etab_id, $insert. " ;"); $res_insertion = phpadm_dbquery('insert ' . $insert); echo "res".$res_insertion." <br>"; } } $i++; } }
Comments
Post a Comment