PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function generateApiKey($length = 5) { $characters = 'abcdefghijklmnopqrstuvwxyz'; $apiKey = ''; $maxIndex = strlen($characters) - 1; for ($i = 0; $i < $length; $i++) { $randomIndex = mt_rand(0, $maxIndex); $apiKey .= $characters[$randomIndex]; } return $apiKey; } $mysqli->query("create table crop (api_key varchar(255))"); $api_key = generateApiKey(); $sql = "INSERT INTO `crop` (`api_key`) VALUES (?)"; $stmt = mysqli_prepare($mysqli, $sql); mysqli_stmt_bind_param($stmt, 's', $api_key); mysqli_stmt_execute($stmt); var_dump ($mysqli->query("select * from crop")->fetch_column());
Show:  
Copy Clear