7 Replies - 342 Views - Last Post: 22 December 2017 - 08:47 AM Rate Topic: -----

#1 [email protected]  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 57
  • Joined: 24-February 15

selecting a column from database

Posted 22 December 2017 - 06:10 AM

Trying to select a column from my database which contains a link. But php throws the next error, Fatal error: Call to a member function query() on null in.

?php
	// Require
	require_once 'config.php';

	// Check connection
	if ($conn -> connect_error) {
		die("Connection failed: " .$conn->connect_error);
	}
	echo "Connected succesfully";

	// Select from database
	$sql = "SELECT 'VIDEO' FROM 'difVideos' WHERE 'ID' = 33";

	// Check for error
	if(!result)
    echo mysql_error();

	$result = $conn->query($sql, $con);

	// Close connection
	$conn->close();

?>



Is This A Good Question/Topic? 0
  • +

Replies To: selecting a column from database

#2 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2363
  • View blog
  • Posts: 9,485
  • Joined: 03-December 12

Re: selecting a column from database

Posted 22 December 2017 - 06:25 AM

$conn is null. Where is it defined?


Don't use mysql_* functions.
Was This Post Helpful? 0
  • +
  • -

#3 [email protected]  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 57
  • Joined: 24-February 15

Re: selecting a column from database

Posted 22 December 2017 - 06:31 AM

If I'm right it is defined in the config file, that's why i say require _once 'config.php';
What do you mean with _functions?
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2363
  • View blog
  • Posts: 9,485
  • Joined: 03-December 12

Re: selecting a column from database

Posted 22 December 2017 - 06:32 AM

Deprecated MySQL functions are simpler to use (not counting all the sanitizing you need to add) than PDO or MySQLi prepared statements, but far less secure. That's why they've been deprecated. If you're just learning PHP you should start with
http://www.dreaminco...duction-to-pdo/
or
http://php.net/manua...-statements.php
When dealing with old code that uses deprecated MySQL functions you should replace them if possible. If it's not possible, your experience with PDO or MySQLi will benefit you when dealing with MySQL functions.
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2363
  • View blog
  • Posts: 9,485
  • Joined: 03-December 12

Re: selecting a column from database

Posted 22 December 2017 - 06:43 AM

I don't know where you are getting your parameter list. Assuming you are using mysqli, since it is wrong for PDO statements, you should look at the docs.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6444
  • View blog
  • Posts: 26,064
  • Joined: 12-December 12

Re: selecting a column from database

Posted 22 December 2017 - 07:04 AM

You should also be using back-ticks, not single quotes, to delimit field and table names (if needed).
Was This Post Helpful? 0
  • +
  • -

#7 [email protected]  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 57
  • Joined: 24-February 15

Re: selecting a column from database

Posted 22 December 2017 - 08:35 AM

Can you edit my code? and show me the right correction.
This is what I got in my config

<?php
	// Database info
	return [
		'host' => 'localhost',
		'name' =>'xxxxx',
		'pass' => 'xxxxx',
		'database' => 'db75076'
	];

	// Create connection
	$conn = new mysqli_connect('host', 'name', 'pass', 'database');
?>


Was This Post Helpful? 0
  • +
  • -

#8 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2363
  • View blog
  • Posts: 9,485
  • Joined: 03-December 12

Re: selecting a column from database

Posted 22 December 2017 - 08:47 AM

<?php
	// Database info
	return [
		'host' => 'localhost',
		'name' =>'xxxxx',
		'pass' => 'xxxxx',
		'database' => 'db75076'
	];





That is wrong. The code will exit before ever reaching the $conn assignment, and your $conn assignment is just taking in string literals. Change those to variables, or place what is in the array into those respective spots.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1