Jump to content

can any one tell me whats wrong with this function


jeppers

Recommended Posts

<?php
function dbConnect($usertype, $connectionType = 'mysqli') {
  $host = 'localhost';
  $db = 'gallery';
  if ($usertype  == 'read') {
$user = 'psread';
$pwd = '####';
  } elseif ($usertype == 'write') {
$user = 'pswrite';
$pwd = '####';
  } else {
exit('Unrecognized connection type');
  }
  if ($connectionType == 'mysqli') {
return new mysqli($host, $user, $pwd, $db) or die ('Cannot open database');
  }
}
?>

 

when i call upon the function i get this message

 

Fatal error: Call to a member function query() on a non-object in C:\webs\phpsolutions\comments.php on line 8

 

from this code

 

<?php
require_once('includes/connection.php');
// connect to MySQL
$conn = dbConnect('write');
// prepare the SQL query
$sql = 'SELECT * FROM images';
// submit the query and capture the result
$result = $conn->query($sql) or die(mysqli_error());
// find out how many records were retrieved
$numRows = $result->num_rows;
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.