2

I am a beginner. I want to get the imageURL from mysql and display the image.

This is my code

<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

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

$url= "SELECT imgURL FROM icon WHERE id = 1 ";
$result = mysql_query($url,$conn);
$array = mysqli_fetch_array($result);

$imageData = base64_encode(file_get_contents($array));
echo '<img src="data:image/jpeg;base64,'.$imageData.'">';*/
?>

I can connect mysql. But there is a problem

Warning: mysql_query() expects parameter 2 to be resource

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result

Warning: file_get_contents(): Filename cannot be empty

Where is the problem? Dont I get any information from mysql?

Community
  • 1
  • 1
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Dec 01 '16 at 12:06
  • Your mixing up the procedural way & the OOP way of mysqli & mysql. May you should take a look at this: http://www.w3schools.com/php/php_mysql_select.asp – Twinfriends Dec 01 '16 at 12:07
  • You cannot use `mysql_query()` after connecting with `new mysqli(.....)` – RiggsFolly Dec 01 '16 at 12:08

0 Answers0