pdo

PDO 查询mysql返回字段整型变为String型解决方法

孤者浪人 提交于 2020-01-07 12:58:12
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> PDO 查询 mysql 返回字段整型变为String型解决方法 使用PDO查询mysql数据库时,执行prepare,execute后,返回的字段数据全都变为字符型。 例如id在数据库中是 Int 的,查询后返回是 String 型。 对于php这种弱类型的语言,影响不大。在做API返回数据时,如果类型与数据库不一致,对于java和Objective C这些强类型,影响就很大了。 解决方法: <?php$pdo = new PDO($dsn, $user, $pass, $param);// 在创建连接后,加入$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);?>1234567 这两句设置的作用 PDO::ATTR_STRINGIFY_FETCHES 提取的时候将数值转换为字符串。 PDO::ATTR_EMULATE_PREPARES 启用或禁用预处理语句的模拟。 更多 PDO setAttribute 可参考: http://php.net/manual/zh/pdo.setattribute.php 顶 0 踩 来源: oschina 链接

How do I convert this PDO code to MySQLi?

无人久伴 提交于 2020-01-07 09:57:49
问题 I'm quite new to PHP and MySQL and I try to learn how to change a code from PDO to MySQLi. Its about a remember me function with a securitytoken and identifier for a login system that I found in the web. I would like to learn and understand how I can change the code from PDO to MySQLi. I know in MySQLi there is a statement create and prepare, also I have to bind parameters and execute. But in this case, I don't know how to start anyway. $pdo = new PDO('mysql:host=localhost;dbname=dbname',

JOIN multiple tables in single query using LEFT OUTER JOIN

女生的网名这么多〃 提交于 2020-01-07 09:23:48
问题 I'm having difficulties using the LEFT OUTER JOIN in multiple tables. My tables are: countries , customer_info , package_types , service_types and shipping_info This is my code so far: $sql = "SELECT shipping_info.shipping_id, shipping_info.weight, shipping_info.width, shipping_info.height, shipping_info.length, shipping_info.cost, shipping_info.status, service_types.service, package_types.package_type, countries1.country AS fromCountry, countries2.country AS toCountry, countries3.country AS

JOIN multiple tables in single query using LEFT OUTER JOIN

百般思念 提交于 2020-01-07 09:23:06
问题 I'm having difficulties using the LEFT OUTER JOIN in multiple tables. My tables are: countries , customer_info , package_types , service_types and shipping_info This is my code so far: $sql = "SELECT shipping_info.shipping_id, shipping_info.weight, shipping_info.width, shipping_info.height, shipping_info.length, shipping_info.cost, shipping_info.status, service_types.service, package_types.package_type, countries1.country AS fromCountry, countries2.country AS toCountry, countries3.country AS

JOIN multiple tables in single query using LEFT OUTER JOIN

女生的网名这么多〃 提交于 2020-01-07 09:23:05
问题 I'm having difficulties using the LEFT OUTER JOIN in multiple tables. My tables are: countries , customer_info , package_types , service_types and shipping_info This is my code so far: $sql = "SELECT shipping_info.shipping_id, shipping_info.weight, shipping_info.width, shipping_info.height, shipping_info.length, shipping_info.cost, shipping_info.status, service_types.service, package_types.package_type, countries1.country AS fromCountry, countries2.country AS toCountry, countries3.country AS

Return results within a given radius using a bounding circle as a 'First Cut' in MySQL

狂风中的少年 提交于 2020-01-07 08:56:13
问题 I was working with Chris Veness' scripts from http://www.movable-type.co.uk I was trying to run a query against a MySQL database to return only rows that fall within a given radius, using his Bounding Circle script. As follows: <?php require 'inc/dbparams.inc.php'; // defines $dsn, $username, $password $db = new PDO($dsn, $username, $password); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); $lat = $_GET['lat']; // latitude of centre of bounding circle in degrees $lon = $_GET

PDO prepared Statements correct?

霸气de小男生 提交于 2020-01-07 08:24:06
问题 I am trying to use some PDO prepared statements for the first time to prevent a SQL Injection. I am quite new to SQL so the prepared statements are very bewildering to me. Do you think my SQL code with prepared statements is correct? <?php if ( $_SERVER["REQUEST_METHOD"] == 'POST' ) { $suche = htmlspecialchars($_POST['suche']); $stmt->bindParam(':suche', $suche); if (!empty($suche)) { $sql = new rex_sql; $sql->debugsql = 0; $stmt = $sql->prepare("SELECT * FROM rex_downloads WHERE dateiname

PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number [closed]

人盡茶涼 提交于 2020-01-07 08:14:04
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I´m trying to do an update with PDO and I´m getting an error that Im not detecting where the problem is. The error is this : PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in $updateCategory->execute(); Someone there have any idea why this is happening? $urledit = $

Fatal error: Call to a member function count() on a non-object in not solved

北慕城南 提交于 2020-01-07 07:56:33
问题 Sorry i think this question has a lot , but I still do not get the solution of this question, so solved my script please:( sorry my bad english. <?php class Validate{ private $_passed = false, $_error = array(), $_db = null; public function __construct(){ $this->_db = DB::getInstance(); } public function check($source, $items = array()){ foreach ($items as $item => $rules) { foreach ($rules as $rule => $rule_value) { $value = trim($source[$item]); $item = escape($item); if($rule === 'required

SQL database value to variable

ε祈祈猫儿з 提交于 2020-01-07 07:49:21
问题 So, I am kinda new to php and mysql, but I have found a login form and adapted it to my needs as I dont have the knowledge to make one my self yet. I added a firstname and surname column into the database and the register form adds the values into the database fine. Now I want to be able to display the firstname and surname onto a restricted page, the reason why I need this is because I want it to say: Welcome Jo Blogs. Below is the register form. <?php session_start(); if( isset($_SESSION[