Jump to content

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;
?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.