Will mysql_connect itself?

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 10, 2012 4:37 pm

Tue Oct 09, 2012 7:28 pm

No, it wont, if you call mysql_connect 3times, it connects 3times.

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Wed Oct 10, 2012 9:40 am

yes, just assign the connect to a variable, and then isset($connection) will determine if it's set.

New php-forum User
New php-forum User
Posts: 137
Joined: Tue Mar 08, 2011 9:25 am

Tue Oct 23, 2012 11:09 am

An alternative would be to create the connection in the script that calls a(); and pass it as an argument to a, then you can handle the connection in the parent structure.

Code: Select all

//do upper parent stuff
$pdo_handle = new PDO('my connection string',$arg1,$arg2);
//do more stuff
$my_important_stuff = a($lala,$pdo_handle);
$my_other_stuff = a($lala2,$pdo_handle);

function a($args_i_need, &$pdo_connection){
   $my_prepared_statement = $pdo_connection->prepare("SELECT * FROM myTable;");
   //do stuff
   return $my_results;
seems an easier way to control connections.

Post Reply