Posts by rray • 66,288 points
1,220 posts
-
2
votes1
answer1623
viewsA: Error using PDO: "Call to a Member Function query() on a non-object in ..."
The problem is the wrong assignment. Instead of assigning the connection in the property $conn it is done in a local variable of the same name. Misconception: $conn = new…
-
6
votes4
answers3460
viewsA: Take letters from name string
You can take the first character of the string, just index the variable to zero. To take the first letter after the space you can use str_pos() that will determine the position of space, with it use…
-
10
votes4
answers402
viewsA: How to remove parentheses of values in an array?
Can use array_map(), to apply an anonymous function to each item in the array. The substitution is on account of the str_replace() looking for ( and ) and swap for nothing. A new array is generated:…
-
4
votes2
answers1260
viewsA: How to insert all array values and avoid $query->execute() with each foreach run?
One way to make a single Insert is to have several VALUES to generate an sql as INSERT INTO teste(nome, email) VALUES (?,?),(?,?),(?,?) Your array is multidimensional, in which case the first step…
-
5
votes1
answer150
viewsA: Mysql query with PDO does not return data
The query should not return results even due to those simple quotes and the jokers (%). That is, the single quotes will undo your placeholder instead of searching %termo digitado% go find %:tl%. To…
-
2
votes1
answer1292
viewsA: How to create a windows environment variable
To create an environment variable it is necessary to have administrator privileges, so just use the command setx Example: setx NOME valor…
-
2
votes1
answer985
viewsA: mysqli_query() expects Parameter 1 to be mysqli, null Given in, how to resolve?
Cannot (nor desired) access global variables within a function. The function addProdutoVenda() does not see the variable $con, so the error ( invalid connection). To solve this, pass the connection…
-
2
votes3
answers2853
viewsA: Pass variable value inside text with echo
The link in the image seems mounted wrong, has a double quote left, remove it Change: <a href="produtos.php?Cliente="'.$_SESSION['Cliente'] .'" class="btn .... aspa a mais ------------------^ To:…
-
8
votes3
answers1401
viewsA: I would like to know what is the function of: {} in the Python language and more specifically within the PRINT function as in this code?
The {0} means the position of replacing that placeholder with a value or variable. The idea is to act as a mask. Such a type of construction avoids over-concatenations. format() reminds the function…
-
7
votes3
answers30488
viewsA: What is the difference between "{ }" and "[ ]" brackets?
Keys { } delimit the structure of an object or whatever properties/characteristics it will have. Square brackets [ ] Indicates that there is more than one element, it is the same array notation. In…
-
5
votes2
answers3232
viewsA: check amount of php character
To count the number of characters in php use the function mb_strlen(). strlen() returns the number of bytes that by knowing can return the same number of characters. Excerpt from the documentation:…
-
7
votes3
answers815
viewsA: In PHP are all variables declared global?
All variables declared in PHP are global? No, there are three types of scopes in PHP that are: conditional, function, and class (attributes, which works a little differently). PHP by default has a…
-
0
votes1
answer5011
viewsA: Error Connection Database; "relation does not exist"
column "name" of relation "product registration" Names of identifiers (tables, field, etc.) with uppercase letters or special characters in Postgresql should be delimited with quotes, otherwise they…
-
6
votes1
answer3967
viewsA: Difference between var_dump and print_r
Basically the differences between print_r()and var_dump() are that the second in addition to displaying the value/structure of the variable shows its type and size in the case of strings. Do not…
-
1
votes1
answer145
viewsA: Suggestions apache tools to develop in php with Postgresql
There are two drivers for connecting to postgres pgsql which allows you to use the function pg_* and the driver for PDO. The instation is done as follows open php.ini and look for the lines:…
-
2
votes1
answer189
viewsA: ODBC PHP / Oracle - UPDATE, INSERT, DELETE
Some banks work in two-way transfers by default. If change (Insert/update/delete) is executed it is not 'practice' on time, it is pending until the commit. There are two ways to solve this problem.…
-
2
votes1
answer344
viewsA: Is it possible to list the columns used in a SELECT in PHP mysqli?
To retrieve the columns used in select use the function/method fetch_fields() which returns information like column name, type, size etc. $db = new mysqli('localhost', 'usuario', 'senha', 'base');…
-
2
votes1
answer166
viewsA: Split string by letter sets with numbers
To capture 'individually' these sets do not break (split) the string, capture using preg_match_all() so you define which parts will pick up from the string. preg_split() will divide the string into…
-
12
votes2
answers701
viewsA: What would be DSN?
DSN is Data Source Name, generally the term defines the settings (ip, user, resource name, port, protocol etc.) necessary for accessing a data source. In the case of the question, it is a database.…
-
4
votes2
answers355
viewsA: Foreign Key does not respect referential integrity
The referential integrity in Mysql works only when tables use the innoDB engine. The first step is to change the type of the tables and then apply the Foreign key, since the values must obey the…
-
4
votes1
answer1727
viewsA: Session Codeigniter
Use the method set_userdata() of the IC session library To assign do: $var = array('nome' => 'teste'); $this->session->set_userdata($var); Or else:…
-
4
votes2
answers73
viewsA: Logic optimization
It is possible to optimize as follows, to detect if the value is 'outside' of the range (greater than the maximum or less than the minimum) and if the alert has already been sent, in this case it…
-
4
votes2
answers828
viewsA: How to differentiate data from two tables with columns of equal names in an SQL request with JOIN?
Since php does not type the column results with the same name has only the value of the last one. The solution is to add an alias to differentiate and obtain the values. This can be done in two ways…
-
2
votes1
answer131
viewsA: Query string works in Phpmyadmin and does not work in PHP
The method query() executes only one SQL statement at a time, the query sends two of them, the first is the variable definition the second select, the delimitation is done by semicolon. The simplest…
-
2
votes1
answer167
viewsA: return of various error via ajax
if is comparing different things (whether done or not and sending email) and uses only a 'bucket' (return array) to play the result. if($query === false){ echo json_encode(array('existe' => 1));…
-
6
votes2
answers59
viewsA: Table of users with same usernames
Makes this column a key Unique that will return an error when an existing value is inserted or updated: ALTER TABLE tabela ADD UNIQUE INDEX `nome_indice` (`coluna`);
-
3
votes1
answer364
viewsA: Return via Ajax data in an input type date with Jquery
Failed to transform the text sent by PHP into a valid json, responseData.Delivery does nothing. Change: $(".delivery-info").val(responseData.Delivery); To: var res = JSON.parse(responseData);…
-
3
votes2
answers45
viewsA: Counting array erroneously
If you need to know how many records were found in the query simply use the function mysqli_num_rows(). If only a form sent by the form removes that foreach else if(isset($_POST['alterar'])){ $sql =…
-
5
votes2
answers2530
viewsA: How to remove all "/" occurrences from a string using Javascript
In javascript a regex is delimited / doesn’t need simple quotes. Change: console.log(str.replace('/\//g','')); To: console.log(str.replace(/\//g,''));…
-
6
votes3
answers89
viewsA: How to parse a string array for a multidimensional array?
Utilize explode() to separate the key ($str[0]) and the value ($str[1]) of each item in the array, after just matching the pair and assigning this element in the new array. $arr = ['MemTotal:…
-
0
votes3
answers137
viewsA: How to parse the return of the __getFunctions() class Soapclient method
You can use the function strpos() to find the position of the first space and of the open prenhesis, with this it is possible to determine which section should be 'cropped' with the function…
-
2
votes2
answers458
viewsA: "expects Parameter 2 to be Resource" error when connecting to the database
There are three ways to make PHP connect with Mysql, the functions (removed from php7) mysql, the PDO and the Mysqli. Question code mixed PDO with removed functions. The simplest solution would be…
-
3
votes3
answers3023
viewsA: Foreach Array incrementing another array
If you are going to mount an array and do an Insert via querybuilder CI, normally the key names should be the column names in the database, in which case you can use the function array_map() to…
-
9
votes4
answers11110
viewsA: How to group SQL results by month and year?
The GROUP BY Mysql does not follow the ansi pattern, which means that in most databases there is a requirement to group all fields that are in the field list (after the word SELECT). This change…
-
20
votes4
answers38157
viewsA: What is XGH (Extreme Go Horse)?
Go Horse is a satire on software development that is basically the joining of people running roles and processes. The Extreme Go Horse is the methodology that suggests which processes should be…
terminologyanswered rray 66,288 -
3
votes2
answers105
viewsA: Logical operators in form validation with php
Another alternative is to use the function array_filter() it will check each item of the array, if empty it will not be returned, ie if there is at least one value it will be evaluated as true in…
-
0
votes1
answer12297
viewsA: PHP Warning Code Error: mysqli_select_db() expects Exactly 2 Parameters, 1 Given
Most Mysqli functions ask for connection as the first argument. The error indicates that two arguments should be passed, but only one was passed. There are two ways to solve the problem the first is…
-
3
votes2
answers7136
viewsA: Find duplicate values in an array
It is also possible to identify the repeated elements with the function array_count_values() that returns an array, where the keys are the elements and the values the number of occurrences, with…
-
3
votes1
answer120
viewsA: As I give echo in array
The query returns an object with the database columns that see properties so treat them properly :COUNT() is not a method. "SELECT COUNT(Title) from ".self::$tablename." GROUP BY category_id" To…
-
6
votes1
answer2067
viewsA: How to extract text in parentheses with regex in php
Failed to specify which character either house in its regex, in case the point .. In other words, you’ll get a parenthesis followed by anything .* followed by a closure of parenthesis. $texto = "As…
-
3
votes3
answers996
views -
0
votes1
answer137
viewsA: how to grab all images with foreach
Leave out everything that does not vary, such as the creation of the Phpmailer object and send it from the email. Use the property Body to format/manipulate/assign email measurement.…
-
4
votes1
answer1193
viewsA: Warning: sqlsrv_fetch_array() expects Parameter 1 to be Resource, Boolean Given in D: xampp5.6 htdocs sysriomed bank-material.php on line 27
Warning: sqlsrv_fetch_array() expects Parameter 1 to be Resource, Boolean Given in This says that there is some kind of error in your query, be it syntax or constraint guitar for example. To be sure…
-
1
votes5
answers200
viewsA: Error when redirecting after sending form
The error seems to be time to get the information from $_POST, where simple quotes are missing in key names in older versions this was allowed and worked in newer ones a Warning is generated ex:…
-
6
votes2
answers1564
viewsA: Is it correct to use the Input tag within a Label tag?
Adding a label to a control (text, checkbox, radio, select) is a way to allow accessibility of your page, remember that some people have problems with motor coordination, so it is not simple to hit…
-
7
votes1
answer829
viewsA: PHP class vs Function
The main feature of object orientation is to join or array, the data structure (usually a type defined by the programmer) class, with behaviors (methods). Some languages force this such as java,…
-
0
votes1
answer63
viewsA: Error in login system using SQL Server. Resource(7) of type (SQL Server Statement)
The message resource(7) of type (SQL Server Statement) is not an error, is a representation in text form of Resource (which can be a query). Your query has been processed with sqlsrv_query() but…
-
4
votes3
answers10321
viewsA: select from date in postgresql database
Since the field is timestamp (date and time) you can cast a (::tipo) for date and make the comparison only with the current date CURRENT_DATE SELECT * FROM tabela Where data_entrevista::date >=…
-
3
votes3
answers6551
viewsA: How to check if a value is date
You can use the class DateTime to convert the value into an object, format it and finally convert it, from there compare the original value ($data) with the object value, this ensures that invalid…
-
2
votes1
answer243
viewsA: PHP - Popular dropdown using a database table name
There is no function matching mysql_list_tables() for Mysqli extension, the way is to make an appointment in the same hand. You can list all tables in the current database, by information_schema or…