Friday, 15 August 2014

Use one or two php scripts for mysql -



Use one or two php scripts for mysql -

i have 1 script of php should check if given user exists in users table, , if not creates it, if yes updates existing user new information.

should create in 1 sql query checks , insert/update or should first utilize 1 php script row count , utilize sec script insert/update new user?

i know sql basics, not strong side.

also solution improve towards client/server communication?

i utilize function:

function exists($detail, $table, $column, $value) { $query = mysqli_query($this->connect, "select `$detail` `$table` `$column` = '$value'"); $count = mysqli_num_rows($query); if($count >= 1) { homecoming true; } else { homecoming false; } }

so if user exists homecoming true else false. after check run function / query update user.

the above function this:

//select `username` `users` `username` = '$username' if(exists('username', 'users', 'username', $username)) { //run code if true } else { //run code if false }

php mysql sql

No comments:

Post a Comment