Is it possible to have two types of MySQL connection on a PHP page?
Currently there is a $link = mysql_connect
and a $mysqli = new mysqli
connections that are accessed via two seperate include
files in PHP.
They both pull data down from a MySQL database but if they are both in the same PHP page, the second connection doesn't work.
Am I missing something really obvious?
mysql
$link = mysql_connect("localhost", "root", "root", "abc");
if(!$link)
{
die('There was a problem connection to the database. Please contact your survey administrator.');
}
mysql_select_db("root");
$query = "SELECT * FROM tresults";
$result = mysql_query($query);
$total = mysql_num_rows($result);
$query1 = "SELECT * FROM trespondent";
$result1 = mysql_query($query1);
$total1 = mysql_num_rows($result1) - 1;
$percent = number_format(($total * 100) / $total1);
mysql_close($link);
}
mysqli
$mysqli = new mysqli("localhost", "root", "root", "abc");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$a = 'q';
$aa = 1;
$r = "$a$aa";
$q = 55;
while($aa <= $q){
$query .= "SELECT COUNT(". $r .") as Responses, (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = -1 ) as NA, (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 1 ) as SD, (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 2 ) as D, (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 3 ) as A, (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 4 ) as SA, ((SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 3 ) + (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 4)) as Pos, ((SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 1 ) + (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 2)) as Neg, (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." >= 1) AS Total, ( ((SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 3 ) + (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." = 4)) / (SELECT COUNT(". $r .") FROM tresults WHERE ". $r ." >= -1) ) *100 AS percentage FROM tresults;";
$aa = $aa + 1;
$r = "$a$aa";
NOTE: The rest of the code and also the close is handled within the PHP page using: $mysqli->close();
if ($mysqli->multi_query($query)) {
$n = 0;
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
$i = 1;
$p = 1;
while ($row = $result->fetch_row()) {
// print_r($row);
$n++;