PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE users ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `user_name` varchar(255) NOT NULL, `user_pass` varchar(255) NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE customers( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `user_id` bigint(20) unsigned NOT NULL, `name` varchar(255) NOT NULL, `address`varchar(255) NOT NULL, PRIMARY KEY (`id`) );
Copy Clear
Copy Format Clear
<?php $q = mysqli_prepare( $mysqli, "INSERT INTO `users` (`name`, `user_name`, `user_pass`) VALUES (?, ?, ?)" ); $q->bind_param("sss", $name, $user_name, $user_pass); $name = 'john'; $user_name = 'johndoe1'; $user_pass = '12345'; $q->execute(); $result = $mysqli->query( 'SELECT `id` from `users` LIMIT 1;' ); $row = $result->fetch_assoc(); $row_user_id = intval( $row['id'] ); $result->free_result(); $q = mysqli_prepare( $mysqli, "INSERT INTO `customers` (`user_id`,`name`,`address`) VALUES (?, ?, ?)" ); $q->bind_param("dss", $user_id, $name, $address); $user_id = $row_user_id; $name = 'john'; $address = 'johndoe1'; $q->execute(); $result = $mysqli->query( 'SELECT users.id,users.name from users INNER JOIN customers ON users.id = customers.user_id LIMIT 1;'); $row = $result->fetch_assoc(); var_dump( $mysqli->error ); var_dump( $row ); $result->free_result();
Show:  
Copy Clear