I have been trying to run my stored procedure using mysql for quite sometime. whenever I use the code below
$link_id = DbConnection::getInstance('mycon')->connectMysql();
$table_count = mysql_query("SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'mycon' AND table_name LIKE 'table_%' ")
while($row = mysql_fetch_array($table_count)){
$table = $row["TABLE_NAME"];
$excute = mysql_query("dummy_2('$table')") or die(mysql_error());
$result = mysql_fetch_assoc($excute);
var_dump($result);
}
it gives an error saying
Commands out of sync; you can't run this command now
Therefore i tried to get this done through PDO .. nevertheless i still getting number of errors since im new in it.
code that i tried.
$pdo =new PDO(DbConnection::getInstance('mycon')->connectMysql());
if($pdo->exec("call dummy_2('$table')"))
{
echo "its working";
}
can any body help me to get the above connection and query done through PDO
connection
$link_id = DbConnection::getInstance('mycon')->connectMysql();
related script
protected $dbConfig;
protected $dbConfigName;
protected $mysql;
protected function __construct($dbConfigName){
$this->dbConfigName = $dbConfigName;
$this->dbConfig = Config_Reader::read($dbConfigName, 'db_con.ini')->database;
}
public static function getInstance($dbConfigName){
if (!isset(self::$instances[$dbConfigName])){
self::$instances[$dbConfigName] = new self($dbConfigName);
}
return self::$instances[$dbConfigName];
}
public function connectMysql(){
if (!is_resource($this->mysql)){
$this->mysql = mysql_connect($this->dbConfig->host, $this->dbConfig->username, $this->dbConfig->password, true);
if (!$this->mysql){
return false;
}
if (mysql_select_db($this->dbConfig->name, $this->mysql)){
return $this->mysql;
}
else{
mysql_close($this->mysql);
$this->mysql = null;
return false;
}
}
return $this->mysql;
}
}