mysqli

PHP: Writing a MYSQL query to CSV

我与影子孤独终老i 提交于 2020-01-02 06:18:10
问题 I'm attempting to write a MySQLi query to a downloadable CSV. The following headers open a stream for the CSV: $fileName = ''; //empty file name, file name is cast later header("Cache=Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename={$fileName}"); header("Expires: 0"); header("Pragma: public"); $fh = @fopen( 'php://output', 'w' ); Below this I have the

PHP Error: “Call to undefined function mysqli_connect()”

你离开我真会死。 提交于 2020-01-02 04:56:18
问题 In PHP I'm getting this error: Call to undefined function mysqli_connect() I checked my php.ini file and there is no ; in front of extension=php_mysql.dll or extension=php_mysqli.dll . I think the I am getting this error because my figuration File (php.ini) Path is C:\Windows . How would I change it to C:\Apache2.2\php\php.ini ? 回答1: On Ubuntu machines you can try: sudo apt-get install php5-mysql since the basic PHP5 install does not include the mysqli_connect function. 回答2: You can set the

php switching to mysqli: num_rows issue

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 12:33:11
问题 I recently started updating some code to MySQL improved extension, and have been successful up until this point: // old code - works $result = mysql_query($sql); if(mysql_num_rows($result) == 1){ $row = mysql_fetch_array($result); echo $row['data']; } // new code - doesn't work $result = $mysqli->query($sql) or trigger_error($mysqli->error." [$sql]"); if($result->num_rows == 1) { $row = $result->fetch_array(); echo $row['data']; } As shown I am trying to use the object oriented style . I get

php switching to mysqli: num_rows issue

こ雲淡風輕ζ 提交于 2020-01-01 12:33:07
问题 I recently started updating some code to MySQL improved extension, and have been successful up until this point: // old code - works $result = mysql_query($sql); if(mysql_num_rows($result) == 1){ $row = mysql_fetch_array($result); echo $row['data']; } // new code - doesn't work $result = $mysqli->query($sql) or trigger_error($mysqli->error." [$sql]"); if($result->num_rows == 1) { $row = $result->fetch_array(); echo $row['data']; } As shown I am trying to use the object oriented style . I get

Converting mysql to mysqli - how to get superglobal connection object?

风格不统一 提交于 2020-01-01 12:01:19
问题 I am trying to convert code from mysql to mysqli. The code uses a single mysql_connect in a file which is included by every other file. mysql_connect returns a MySQL link identifier that is a superglobal so you can rely on having a database connection available in any of your own functions. It looks like with mysqli_connect this is not the case, the object returned isn't global. Does this mean I have to add : global $mysqli; at the top of every function, or is there an way of making it a

PHP MySQLi INSERT not working, no errors

狂风中的少年 提交于 2020-01-01 10:52:54
问题 Different from this question, but similar in that I don't get an error when adding information to my database. $sql = "INSERT INTO 'nlcc_ver1'.'tUsers' ('userID', 'userName', 'userPassword', 'userHash', 'user_first_name', 'user_last_name', 'user_corps', 'is_admin', 'is_trg', 'is_sup', 'is_co') VALUES (NULL, '" . $userName . "', '" . $hash . "', '" . $salt . "', '" . $f_name . "', '" . $l_name . "', '" . $corps . "', '" . $admin . "', '" . $trg . "', '" . $sup . "', '" . $co . "')"; $hostname

mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

时光怂恿深爱的人放手 提交于 2020-01-01 09:58:12
问题 im working on a website which mostly uses the database. the problem is that im geting the following error: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known I cant figure out how to fix it. I've penta-checked the connect and it seems to be okay. function connect($hostname, $username, $password, $database) { $conid = mysqli_connect($hostname, $username, $password, TRUE); if($conid == FALSE) { if(DEBUG == TRUE) { show_error("MySQL Connection using `

SQL syntax error MariaDB server version for the right syntax to use near 'WHERE ID = 4' at line 1

拈花ヽ惹草 提交于 2020-01-01 00:43:42
问题 I have this line of SQL : $sql = "SELECT ID, ListStID, ListEmail, Title FROM $entry_database WHERE ID = '". $ReqBookID ."'"; $result = mysqli_query($conn, $sql); As you can see, I am selecting an entry's ID, ListStID, ListEmail and Title Column if ID is equal to a string of numbers (or text), which is given by user in a form. Everything is ok, and I don't get any syntax error when I write the code (I am using a code editor software. However, when I use it online, I get this error: Error:

MySQLi Prepared Statements and Transactions

China☆狼群 提交于 2019-12-31 22:22:15
问题 Is there a way to do transactions with prepared statements? I mean can I use the following example with $mysqli->autocommit(FALSE); and $mysqli->commit( ); and $mysqli->rollback( ); //Preparing the statment $insert_stmt=$mysqli->prepare("INSERT INTO x VALUES(?,?)") or die($mysqli->error); //associate variables with the input parameters $insert_stmt->bind_param("is", $my_number,$my_string); //i=integer //Execute the statement multiple times.... for ($my_number = 1; $my_number <= 10; $my_number

PHP and MySQLi close()

无人久伴 提交于 2019-12-31 08:34:55
问题 I am new to MySQL and PHP and am attempting to make my own CMS to help make managing my websites easier. Can someone explain mysqli's close() function? Is it necessary? What exactly does it do? I heard that after PHP runs its script that it closes the connection, is that true? Lastly, is there a security issue when not closing your connection to the database? 回答1: Is it necessary? No, PHP will end your connection after it finishes running. What exactly does it do? The reverse of mysqli