mysqli

Is there any need to use fetch_object or fetch_array?

假如想象 提交于 2021-02-04 21:39:14
问题 I recently found out that I can print results from database without using mysqli_fetch_object function. So for example: Let's say we have simple sql select statment which would be executed by using something like this: $conn = mysqli_connect('localhost', 'root', '', 'example_db'); $result = mysqli_query($conn, "SELECT * FROM users"); Next step would be something like this: while($row = mysqli_fetch_object($result)) echo $row->username Where username is corresponding column name in table of

Is there any need to use fetch_object or fetch_array?

耗尽温柔 提交于 2021-02-04 21:38:46
问题 I recently found out that I can print results from database without using mysqli_fetch_object function. So for example: Let's say we have simple sql select statment which would be executed by using something like this: $conn = mysqli_connect('localhost', 'root', '', 'example_db'); $result = mysqli_query($conn, "SELECT * FROM users"); Next step would be something like this: while($row = mysqli_fetch_object($result)) echo $row->username Where username is corresponding column name in table of

How to get comma separated values from database

与世无争的帅哥 提交于 2021-02-04 21:06:34
问题 I have the following mysqli query, and I want to implode the array that's outputted into a (1,2,3,4) type format. Here's the query and the asoc array code: $user_categories = mysqli_query($connect, "SELECT sub_cat FROM subscriptions WHERE sub_user_id = '$user_id'"); $category_ids = mysqli_fetch_all($user_categories,MYSQLI_NUM); print_r($category_ids); $category_ids = implode(", ",$category_ids); I then get the following output, and I can't seem to isolate the values... Array ( [0] => Array (

Mysqli prepared statement column with variable

懵懂的女人 提交于 2021-02-04 06:30:30
问题 My code has to update a query with a custom variable as column. How can I safely bind the column name? $username = 'MyUsername'; $rank = 'Administrator'; $server = 'Node5'; $stmt = $connection->prepare("UPDATE staff_members SET ?=? WHERE Username=? LIMIT 1"); $stmt->bind_param("sss", $server, $rank, $username); $stmt->execute(); 回答1: It's impossible to use a parameter for a column or a table name. Instead, they must be explicitly filtered out before use, using a white list approach. // define

Mysqli prepared statement column with variable

穿精又带淫゛_ 提交于 2021-02-04 06:30:26
问题 My code has to update a query with a custom variable as column. How can I safely bind the column name? $username = 'MyUsername'; $rank = 'Administrator'; $server = 'Node5'; $stmt = $connection->prepare("UPDATE staff_members SET ?=? WHERE Username=? LIMIT 1"); $stmt->bind_param("sss", $server, $rank, $username); $stmt->execute(); 回答1: It's impossible to use a parameter for a column or a table name. Instead, they must be explicitly filtered out before use, using a white list approach. // define

Is it possible to combine mysqli prepared statement with multiple inserts?

一笑奈何 提交于 2021-02-04 06:13:38
问题 I am well-versed in the old php mysql extension. I am working on my first script that uses the mysqli extension. I am going to be inserting a large number of rows into a table that are being generated dynamically. Is it possible to use a prepared statement to insert multiple rows into a table without previously knowing the number of new rows that will be inserted each time? $stmt = $mysqli->prepare("INSERT INTO `activity` (`id`, `name`, `type`) VALUES ?, ?, ?;"); If that isn't possible, which

How to enable mysqli support for PHP's CLI

做~自己de王妃 提交于 2021-02-02 09:25:46
问题 I'm using Ubuntu LTS 14.04 operating system and I'm trying to test my PHP scripts in the PHP CLI, but wherever my code attempts to connect to MySQL, with commands such as... $mysqli = mysqli_connect($host,$user,$password,$database); ...,I get the following error: Fatal error: Call to undefined function mysqli_connect()... I've reviewed /etc/php5/cli/php.ini AND /etc/php5/apache2/php.ini and have found no difference. I think that I must enable mysqli support for the command line interface (CLI

How to enable mysqli support for PHP's CLI

浪尽此生 提交于 2021-02-02 09:25:04
问题 I'm using Ubuntu LTS 14.04 operating system and I'm trying to test my PHP scripts in the PHP CLI, but wherever my code attempts to connect to MySQL, with commands such as... $mysqli = mysqli_connect($host,$user,$password,$database); ...,I get the following error: Fatal error: Call to undefined function mysqli_connect()... I've reviewed /etc/php5/cli/php.ini AND /etc/php5/apache2/php.ini and have found no difference. I think that I must enable mysqli support for the command line interface (CLI

How to run multiple insert query in SQL using PHP in one go?

喜夏-厌秋 提交于 2021-02-02 09:09:42
问题 I want to run mysql queries to insert data from a custom html form. Here I have to insert multiple set of data, some data to one table and some to other. Currently I am using the simple approach to send data to php page using jquery ajax and run multiple mysqli_query() functions one after another. But I guess when there will be large number of users, there will be problems related to speed. So can anyone suggest me a better way to do the same. There are 5 tables in the database and each table

How to run multiple insert query in SQL using PHP in one go?

那年仲夏 提交于 2021-02-02 09:04:05
问题 I want to run mysql queries to insert data from a custom html form. Here I have to insert multiple set of data, some data to one table and some to other. Currently I am using the simple approach to send data to php page using jquery ajax and run multiple mysqli_query() functions one after another. But I guess when there will be large number of users, there will be problems related to speed. So can anyone suggest me a better way to do the same. There are 5 tables in the database and each table