php mysql 笔试题


以下是一些 PHP 和 MySQL 相关的笔试题: PHP 部分 基础语法类 1. 写出一个 PHP 函数,用于计算两个数的和。 ```php <?php // 定义一个名为 sum 的函数,接收两个参数 $num1 和 $num2 function sum($num1, $num2) { // 返回两个参数的和 return $num1 + $num2; } // 调用函数并输出结果 echo sum(3, 5); ?> ``` 2. 解释 PHP 中 `isset()` 和 `empty()` 函数的区别。 `isset()` 函数用于检查一个变量是否已经设置并且不是 `null`。如果变量存在且不为 `null`,则返回 `true`,否则返回 `false`。 `empty()` 函数用于检查一个变量是否为空。如果变量为 `""`、`0`、`"0"`、`null`、`false`、`array()` 等情况,`empty()` 会返回 `true`,否则返回 `false`。 面向对象编程类 3. 创建一个简单的 PHP 类 `Person`,包含属性 `name` 和 `age`,以及一个方法 `introduce` 用于输出个人信息。 ```php <?php // 定义一个名为 Person 的类 class Person { // 定义公共属性 $name 和 $age public $name; public $age; // 构造函数,用于初始化对象的属性 public function __construct($name, $age) { $this->name = $name; $this->age = $age; } // 定义一个名为 introduce 的方法,用于输出个人信息 public function introduce() { echo "My name is {$this->name} and I am {$this->age} years old."; } } // 创建一个 Person 对象 $person = new Person("John", 30); // 调用 introduce 方法 $person->introduce(); ?> ``` MySQL 部分 基础查询类 4. 假设有一个 `users` 表,包含字段 `id`、`name`、`email`,写出查询所有用户信息的 SQL 语句。 ```sql SELECT * FROM users; ``` 5. 写出一个 SQL 语句,查询 `users` 表中 `name` 为 `John` 的用户信息。 ```sql SELECT * FROM users WHERE name = 'John'; ``` 表操作类 6. 写出创建一个 `products` 表的 SQL 语句,包含字段 `id`(自增主键)、`name`(字符串类型)、`price`(浮点类型)。 ```sql CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), price FLOAT ); ``` PHP 与 MySQL 结合部分 7. 写出一个 PHP 脚本,连接到 MySQL 数据库,查询 `users` 表中的所有用户信息并输出。 ```php <?php // 数据库连接信息 $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database_name"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检查连接是否成功 if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // 查询语句 $sql = "SELECT * FROM users"; $result = $conn->query($sql); // 检查查询结果 if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["name"]. " - Email: " . $row["email"]. "<br>"; } } else { echo "0 results"; } // 关闭连接 $conn->close(); ?> ``` 额外需要注意的逻辑点 1. 在使用 PHP 连接 MySQL 时,要确保数据库连接信息的正确性,避免因连接信息错误导致无法连接数据库。 2. 在编写 SQL 语句时,要注意字符串类型的值需要用单引号或双引号括起来,避免语法错误。 3. 在处理数据库查询结果时,要检查结果集是否为空,避免因结果集为空而导致的错误。 [2025-06-13 21:38:02 | AI写代码神器 | 1016点数解答]
- master.driver = com.mysql.jdbc.driver master.url = jdbc:mysql://10.9.1.210:3306/drdisplayv3_dev?usessl=false&useunicode=true&characterencoding=utf-8&zerodatetimebehavior=converttonull&transformedbitisboolean=true master.username = root master.password = root 副表配置 slave.driver = com.mysql.jdbc.driver slave.url = jdbc:mysql://localhost:3306/drdisplay?usessl=false&useunicode=true&characterencoding=utf-8&zerodatetimebehavior=converttonull&transformedbitisboolean=true slave.username = root slave.pas(92点数解答 | 2024-06-26 15:47:44)281
- master.driver = com.mysql.jdbc.driver master.url = jdbc:mysql://10.9.1.210:3306/drdisplayv3_dev?usessl=false&useunicode=true&characterencoding=utf-8&zerodatetimebehavior=converttonull&transformedbitisboolean=true master.username = root master.password = root 副表配置 slave.driver = com.mysql.jdbc.driver slave.url = jdbc:mysql://localhost:3306/drdisplay?usessl=false&useunicode=true&characterencoding=utf-8&zerodatetimebehavior=converttonull&transformedbitisboolean=true slave.username = root slave.pass(210点数解答 | 2024-06-26 15:49:53)260
- <filesmatch "\.(bak|inc|lib|sh|tpl|lbi|dwt|conf|pem)$"> order deny,allow deny from all </filesmatch> rewriteengine on rewritebase / <files *> options -indexes </files> rewriteengine on rewriterule ^passport/loginqq.php(.*) passport/loginqq$1 [qsa] rewriterule ^passport/$ /passport\.php [qsa,l] rewriterule ^passport/([a-za-z0-9_]+)$ /passport.\php?module=$1 [qsa,l] rewriterule ^passport/([a-za-z0-9_]+)?redirecturl=(.(165点数解答 | 2024-09-12 17:05:58)178
- <?php if (($this->options->closelun == '1') && ($this->fields->pinglun !='0')):?> <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $GLOBALS['piua'] = $this->options->piua; function threadedComments($comments, $options) { $commentClass = ''; if ($comments->authorId) { if ($comments->authorId == $comments->ownerId) { $commentClass .= ' comment-by-author'; } else { $commentClass .= ' comment-by-user'; } } $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent'; ?(718点数解答 | 2025-08-08 13:24:09)85
- <?php if (($this->options->closelun == '1') && ($this->fields->pinglun !='0')):?> <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $GLOBALS['piua'] = $this->options->piua; function threadedComments($comments, $options) { $commentClass = ''; if ($comments->authorId) { if ($comments->authorId == $comments->ownerId) { $commentClass .= ' comment-by-author'; } else { $commentClass .= ' comment-by-user'; } } $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent'; ?(2007点数解答 | 2025-08-08 13:25:08)178
- 建立一个用于开发 PHP+JavaScript+mysql 程序的 AI 辅助平台,需要结合代码理解、智能生成、实时协作等核心能力,同时适配 PHP 后端与 JS 前端的开发特性。给出搭建的详细步骤(1713点数解答 | 2025-07-28 23:37:41)95
- 建立一个用于开发 PHP+JavaScript+mysql 程序的 AI 辅助平台,需要结合代码理解、智能生成、实时协作等核心能力,同时适配 PHP 后端与 JS 前端的开发特性。给出搭建的详细步骤(1319点数解答 | 2025-07-29 02:10:54)96
- label3 = tk.label(window, text="解析通道") label3.grid(row=2) site = [('线路一', 'https://www.1717yun.com/jx/ty.php'), ('线路二', 'https://jx.jsonplayer.com/player/'), ('线路三', 'https://yparse.jn1.cc/index.php')] 更新线路网址(133点数解答 | 2024-08-02 14:50:54)345
- 通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:\/\/ugc(262点数解答 | 2024-09-09 04:47:49)207
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:(291点数解答 | 2024-09-09 04:49:12)253
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:(312点数解答 | 2024-09-09 04:49:45)372
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:(804点数解答 | 2024-09-09 04:51:29)208