MySQL Forums
Forum List  »  PHP

Input Query string from a file
Posted by: Douglas Moxley
Date: September 15, 2017 07:40PM

Hello fellow members,

I've been working for hours trying to get past the error of reading in the contents of an input file into a query string. I've tried just about every suggestion on the web with no success. Any advice would be greatly appreciated. Below is the code showing where I am stuck.

Thank you!


require('dbconnect.php'); /* CREDENTIALS */

// Create Connection
$dbLink = new mysqli($DBHOST, $DBUSER, $DBPASS, $DBNAME)
or exit( mysqli_connect_error() ); /* HANDLE POSSIBLE DB ERRORS */

// Check Connection
if ($mysqli->connect_error) {
die("Connection failed : " . $dbLink->connect_error);

/* ###### Start where I am stuck ###### */

// Query the database
$query = file_get_contents('c:\\xampp\htdocs\queries\\file_name.txt');
if ($query === false)
// treat error
} else {

// handle good case

/* ###### End where I am stuck ###### */

/* Here is the error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"SELECT * FROM player_tbl"' at line 1 */

$result = mysqli_query($dbLink, $query)
or exit( mysqli_error($dbLink) );

$row = mysqli_fetch_array($result)
or exit( mysqli_error($dbLink) );

echo $result;



// Close the mysql connection

Options: ReplyQuote

Written By
Input Query string from a file
September 15, 2017 07:40PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.